package mysql

import (
	"gorm.io/gorm"
	"time"
)

type HouseOrder struct {
	gorm.Model
	OrderNumber string    `gorm:"type:varchar(50);not null;"`
	UserId      int64     `gorm:"type:int(11);not null;"`
	HouseId     int64     `gorm:"type:int(11);not null;"`
	BeginDate   time.Time `gorm:"type:datetime;not null;"`
	EndDate     time.Time `gorm:"type:datetime;not null;"`
	HousePrice  int64     `gorm:"type:int(11);not null;"`
	Amount      int64     `gorm:"type:int(11);not null;"`
	Status      string    `gorm:"type:varchar(20);not null;"`
}

func CreateHouseOrder(HouseOrder HouseOrder) HouseOrder {
	db.Create(&HouseOrder)
	return HouseOrder
}
func HouseOrderList(page int64, search string) (string, []*HouseOrder) {
	var order []*HouseOrder
	var pageSize = 5
	if search != "" {
		db.Where("goods_name like?", "%"+search+"%").Limit(pageSize).Find(&order)
		return search, order
	}
	pageLimit := int(page-1) * pageSize
	db.Limit(pageLimit).Find(&order).Limit(pageSize).Find(&order)
	return "", order
}
